﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ERPStore.Extensions;

namespace ERPStore.Exporter
{
	public static class TaskHelper
	{
		public static ERPStore.Models.TaskEntry CreateCatalogsTask()
		{
			var task = new ERPStore.Models.TaskEntry();
			task.Period = ERPStore.Models.ScheduledTaskTimePeriod.Day;
			task.Interval = 1;
			task.StartHour = 21;
			task.StartMinute = 30;
			task.IsParallelizable = false;

			task.DelayedStart = 60 * 5;
			task.NextRunningDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 21, 30, 0);
			task.StartedCount = 1;

			task.Name = "ExportCatalog";

			var exportList = GlobalConfiguration.Configuration.DependencyResolver.GetServices<Providers.IExport>().ToList();
			exportList.RemoveAll(i => i.Settings == null);
			exportList.RemoveAll(i => !i.Settings.Enabled);

			var parameters = new Dictionary<string, object>();
			parameters.Add("ExportList", exportList);
			parameters.Add("ForceExport", false);

			task.WorkflowProperties = parameters;

			task.GetActivityInstance = () => new Workflows.GenerateCatalogs();
			return task;
		}

		public static ERPStore.Models.TaskEntry CreateBanishedProductCleanerTask()
		{
			var task = new ERPStore.Models.TaskEntry();
			task.Period = ERPStore.Models.ScheduledTaskTimePeriod.Day;
			task.Interval = 1;
			task.StartHour = 1;
			task.StartMinute = 30;
			task.Name = "Drop expired banished produts";
			task.DelayedStart = 60 * 5;

			task.GetActivityInstance = () => new Workflows.Activities.DropBanishedExpiration();

			return task;
		}

	}
}
